/* 主要实现网关子服务的服务器搭建 */

#include "gateway_server.hpp"

DEFINE_bool(run_mode, false, "程序的运行模式， false-调试； true-发布");
DEFINE_string(log_file, "", "发布模式下，用于指定日志的输出文件");
DEFINE_int32(log_level, 0, "发布模式下，用于指定日志输出等级");

DEFINE_string(registry_host, "127.0.0.1:2379", "服务注册中心地址");
DEFINE_string(base_service, "/service", "服务监控根目录");

DEFINE_int32(http_listen_port, 9000, "HTTP服务器监听端口");
DEFINE_int32(websocket_listen_port, 9001, "WebSocket服务器监听端口");


DEFINE_string(file_service, "/service/file_service", "文件管理子服务名称");
DEFINE_string(friend_service, "/service/friend_service", "好友管理子服务名称");
DEFINE_string(message_service, "/service/message_service", "消息存储子服务名称");
DEFINE_string(speech_service, "/service/speech_service", "语音识别子服务名称");
DEFINE_string(transmite_service, "/service/transmite_service", "消息转发子服务名称");
DEFINE_string(user_service, "/service/user_service", "用户管理子服务名称");


//Redis相关
DEFINE_string(redis_host, "127.0.0.1", "这是Redis服务器的IP地址, 格式: 127.0.0.1");
DEFINE_int32(redis_port, 6379, "这个是Redis服务器的端口, 格式： 6379");
DEFINE_int32(redis_db, 0, "Redis默认库的编号, 默认为0号");
DEFINE_bool(redis_keep_alive, true, "是否进行长连接保活");





int main(int argc, char* argv[])
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    ChatSystem::InitLogger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);

    //关闭brpc的默认日志输出
    logging::LoggingSettings settings;
    settings.logging_dest = logging::LoggingDestination::LOG_TO_NONE;
    logging::InitLogging(settings);
    
    ChatSystem::GatewayServerBuilder gatewayServerBuilder;

    gatewayServerBuilder.make_redis_object(FLAGS_redis_host, FLAGS_redis_port, FLAGS_redis_db, FLAGS_redis_keep_alive);

    gatewayServerBuilder.make_server_object(FLAGS_websocket_listen_port, FLAGS_http_listen_port);

    gatewayServerBuilder.make_discovery_object(FLAGS_registry_host, 
            FLAGS_base_service, 
            FLAGS_file_service, 
            FLAGS_friend_service, 
            FLAGS_message_service, 
            FLAGS_speech_service, 
            FLAGS_transmite_service, 
            FLAGS_user_service);

    auto server = gatewayServerBuilder.build();
    
    server->start();
    return 0;
}

